type AjaxUrlPrefix = 'api' | 'energy' | 'compute'

/**
 * ? 通过下标获取路径，前缀应与环境变量中的地址顺序对应
 */
const baseUrlArr: `/${AjaxUrlPrefix}`[] = [
  '/api',
  '/energy',
  '/compute',
]
const isDevelopment
  = import.meta.env.VITE_ENV === 'development'
const baseUrlTarget = import.meta.env.VITE_BASE_URL.split(
  ',',
)
// console.warn(baseUrlTarget);

/**
 * ## 获取访问请求地址
 * ### /api 系统 [8093]
 * ### /energy 能源 [8092]
 * ### /compute 计算 [8096]
 * @param {string} url [请求地址]
 * @param {`/${AjaxUrlPrefix}`} baseUrl [请求基址,默认为/api]
 * @default
 */
export function getAjaxBaseUrl(url: string, baseUrl: `/${AjaxUrlPrefix}` = '/api') {
  if (isDevelopment)
    return `${baseUrl}${url}`

  const ORIGINS = {
    '/api': SERVICE_BASIC,
    '/energy': SERVICE_ENERGY,
    '/compute': SERVICE_CALCENGINE,
  }
  return ORIGINS[baseUrl] + url
}
